Update Android.bp by running cargo_embargo am: 4fef949c73 Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/strsim/+/3096364 Change-Id: Ic0818998763ab638bfb7e1498433a3ae3740dcf6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 
tree: 1e2135474e248c29cdec7f7b9819ce719e7ef652
  1. benches/
  2. src/
  3. tests/
  4. .cargo_vcs_info.json
  5. .editorconfig
  6. .gitattributes
  7. .gitignore
  8. Android.bp
  9. Cargo.toml
  10. cargo_embargo.json
  11. CHANGELOG.md
  12. LICENSE
  13. METADATA
  14. MODULE_LICENSE_MIT
  15. OWNERS
  16. README.md
README.md

strsim-rs

Crates.io Crates.io CI status unsafe forbidden

Rust implementations of string similarity metrics:

The normalized versions return values between 0.0 and 1.0, where 1.0 means an exact match.

There are also generic versions of the functions for non-string inputs.

Installation

strsim is available on crates.io. Add it to your project:

cargo add strsim 

Usage

Go to Docs.rs for the full documentation. You can also clone the repo, and run $ cargo doc --open.

Examples

extern crate strsim; use strsim::{hamming, levenshtein, normalized_levenshtein, osa_distance, damerau_levenshtein, normalized_damerau_levenshtein, jaro, jaro_winkler, sorensen_dice}; fn main() { match hamming("hamming", "hammers") { Ok(distance) => assert_eq!(3, distance), Err(why) => panic!("{:?}", why) } assert_eq!(levenshtein("kitten", "sitting"), 3); assert!((normalized_levenshtein("kitten", "sitting") - 0.571).abs() < 0.001); assert_eq!(osa_distance("ac", "cba"), 3); assert_eq!(damerau_levenshtein("ac", "cba"), 2); assert!((normalized_damerau_levenshtein("levenshtein", "löwenbräu") - 0.272).abs() < 0.001); assert!((jaro("Friedrich Nietzsche", "Jean-Paul Sartre") - 0.392).abs() < 0.001); assert!((jaro_winkler("cheeseburger", "cheese fries") - 0.911).abs() < 0.001); assert_eq!(sorensen_dice("web applications", "applications of the web"), 0.7878787878787878); } 

Using the generic versions of the functions:

extern crate strsim; use strsim::generic_levenshtein; fn main() { assert_eq!(2, generic_levenshtein(&[1, 2, 3], &[0, 2, 5])); } 

Contributing

If you don't want to install Rust itself, you can run $ ./dev for a development CLI if you have Docker installed.

Benchmarks require a Nightly toolchain. Run $ cargo +nightly bench.

License

MIT